<template>
  <div class="preview_content">
    <home-header-nav></home-header-nav>
    <div class="preview_body">
      <span v-if="showPreBtn" class="float_icon left" @click="onPre">
        <van-icon name="play" color="rgba(255,255,255, .5)"></van-icon>
      </span>
      <span v-if="showNextBtn" class="float_icon right" @click="onNext">
        <van-icon name="play" color="rgba(255,255,255, .5)"></van-icon>
      </span>
        <div class="preview_item">
          <div class="preview_img">
            <video
              :id="`videoRef${goodsInfo.goodsId}`"
              v-if="goodsInfo.indexFileType === '2'"
              class="video-js vjs-big-play-centered"
              :height="pxToPx(430)"
              :width="pxToPx(336)"
            >
              <source :src="goodsInfo.filePath" type="video/mp4" />
            </video>
            <img v-else :src="goodsInfo.filePath" />
            <span class="preview_count">最近{{ goodsInfo.browseNo?goodsInfo.browseNo:0 }}人访问过</span>
            <ul class="tag_list">
              <li
                v-for="(label, index) in goodsInfo.labels"
                :key="index"
                class="tag_item"
              >
                {{ label.labelName }}
              </li>
            </ul>
          </div>
          <div class="preview_bottom">
            <div class="title">{{ goodsInfo.subGoodsName }}</div>
            <div class="sub_title">
              <span v-for="(price, index) in goodsInfo.prices" :key="index">{{
                price.detail
              }}</span>
            </div>
            <div class="button_group">
              <van-button
                type="primary"
                class="select_button"
                @click="onSelect(goodsInfo.belongs)"
                >联系一下</van-button
              >
              <van-button
                type="default"
                class="more_button"
                @click="gotoDetail()"
                >更多信息</van-button
              >
            </div>
          </div>
        </div>
    </div>
    <div class="page_footer">
<!--      <div>精选</div>-->
      <div @click="gotoList()">更多</div>
    </div>
  </div>
</template>
<script setup>
import HomeHeaderNav from "@/components/HomeHeaderNav.vue";
import {ref, onMounted, toRaw, reactive} from "vue";
import { useRouter, useRoute } from "vue-router";
import { pxToPx } from "@/utils";
import "video.js/dist/video-js.css";
import {
  fileServer, selectByIdWithBrowse, toPath,
} from "@/network/api.js";

const router = useRouter();
const routeQuery = useRoute().query;

const goodsInfo = ref({
  goodsId:routeQuery.goodsId,
});

onMounted(() => {
  selectByIdWithBrowse({
    goodsId: routeQuery.goodsId,
  }).then((res) => {
    if (res?.data?.data) {
      goodsInfo.value.goodsName = res.data.data.goodsName;
      goodsInfo.value.browseNo = res.data.data.browseNo;
      goodsInfo.value.subGoodsName = res.data.data.subGoodsName;
      goodsInfo.value.detail = res.data.data.detail;
      goodsInfo.value.indexFileType = res.data.data.indexFileType;
      goodsInfo.value.prices = res.data.data.prices || [];
      goodsInfo.value.fbFiles = res.data.data.fbFiles || [];
      goodsInfo.value.labels = res.data.data.labels || [];
      goodsInfo.value.filePath = fileServer + res.data.data.indexFilePath;
      goodsInfo.value.belongs = res.data.data.belongs;
    }
  });
});

const onSelect = (toUser) => {
  window.location.href = toPath + toUser;
};

const gotoDetail = () => {
  const queryParams = {goodsParam:JSON.stringify(goodsInfo.value)};
  router.push({
    name: "detail",
    query:queryParams,
  });
};
const gotoList = () => {
  router.push({
    name: "home",
    query:{currentPage:routeQuery.currentPage}
  });
};
</script>
<style lang="scss" scoped>
.preview_content {
  .preview_body {
    padding: 0 12px;
    .float_icon {
      position: fixed;
      top: 40%;
      z-index: 100;
    }
    .left {
      left: 10px;
      transform: rotate(180deg) scaleY(1.5);
    }
    .right {
      right: 10px;
      transform: scaleY(1.5);
    }

    .preview_item {
      .preview_img {
        position: relative;
        width: 100%;
        height: 430px;
        background: #1e1e1e;
        display: flex;
        justify-content: center;
        align-items: center;
        img,
        video {
          height: 100%;
          width: 100%;
          object-fit: cover;
        }
        :deep(.vjs-paused) {
          .vjs-big-play-button {
            display: block;
          }
        }
        :deep(.vjs-paused.vjs-has-started) {
          .vjs-big-play-button {
            display: block;
          }
        }
        .preview_count {
          position: absolute;
          top: 10px;
          left: 10px;
          font-size: 12px;
          display: inline-block;
          border-radius: 12px;
          background: #ffffff;
          color: #969799;
          padding: 2px 4px;
        }
        .tag_list {
          width: calc(100% - 20px);
          padding: 8px 10px;
          position: absolute;
          bottom: 27px;
          display: flex;
          flex-direction: row;
          flex-wrap: wrap;
          justify-content: space-between;
          row-gap: 10px;
          .tag_item {
            width: 30%;
            font-size: 12px;
            display: inline-block;
            border-radius: 12px;
            background: #ffffff;
            padding: 2px 4px;
            text-align: center;
            color: #969799;
          }
        }
      }
    }
    .preview_bottom {
      margin-top: 12px;
      width: 100%;
      .title {
        font-weight: bold;
        font-size: 18px;
        text-align: center;
      }
      .sub_title {
        margin-top: 14px;
        font-size: 14px;
        & span {
          display: inline-block;
          margin-right: 40px;
          margin-bottom: 10px;
          white-space: nowrap;
        }
      }
      .button_group {
        text-align: center;
        width: 100%;
        .select_button {
          width: 190px;
        }
        .more_button {
          margin-left: 10px;
          width: 90px;
        }
      }
    }
  }
  .page_footer {
    position: fixed;
    bottom: 0;
    left: 0;
    height: 36px;
    font-size: 12px;
    width: 100%;
    background: #007acc;
    color: #ffffff;
    display: flex;
    justify-content: space-around;
    align-items: center;
  }
}
</style>
